Symfony Debug to Error Handler Component
Since symfony 4.4 the symfony/debug component is deprecated.
The “\Symfony\Component\Debug\ErrorHandler” class is deprecated since Symfony 4.4, use “\Symfony\Component\ErrorHandler\ErrorHandler”
Running unit tests on Mascot, I noticed lots of warnings.
But it was not easy as changing Symfony\Component\Debug\ExceptionHandler to Symfony\Component\ErrorHandler\ErrorHandler.
Assume we have something as below
37 38 39 40 41 42 43 44 <?php $handler = new \Symfony\Component\Debug\ExceptionHandler($debug); $exception = $event->getThrowable(); if (!$exception instanceof FlattenException) { $exception = FlattenException::create($exception); } $response = Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders())->setCharset(ini_get('default_charset')); $event->setResponse($response); The Symfony\Component\ErrorHandler\ErrorHandler has no getHtml method.
building modular applications with psr 7
PSR-7, the HTTP message interfaces opened a new door of creating modular applications.
Sadly many of the PSR-7 implementations added many helper methods.
So if someone is creating a library that needs a PSR-7 implementations they tie the particular library with the PSR-7 implementation and use these convinient helper methods.
So was PSR-15: interfaces for HTTP Middleware and PSR-17: interfaces for HTTP Factories was proposed.
When creating a module one of the most challenging part is how to serve the javascript, css and images.
using cakephp migration as standalone
Cakephp version 3 have a nice ORM. When using the cakephp/orm, it may be nice to integrate cakephp/migration than any other migration libraries, even though it uses phinx under the hood.
Lets see how we can install and integrate cakephp/migration in our application.
composer require cakephp/migrations:dev-master The dev-master is currently passed for we need the latest version of master branch. Before this pull request, it was having dependency on cakephp/cakephp, which is not needed.
aura dot di 2 dot x to 3 dot x upgrade guide
3.x has a very minimal BC break. But if you are not sure what are they, then you may feel the pain. I am trying to document most of them, incase I missed please edit and send a pull request.
I will try to eventually pushed to the main Aura.Di repo.
BC Breaks Instantiation The way di container is instantiated has been changed from
<?php use Aura\Di\Container; use Aura\Di\Factory; use Aura\Di\ContainerBuilder; $di = new Container(new Factory); // or $container_builder = new ContainerBuilder(); $di = $container_builder->newInstance( array(), array(), $auto_resolve = false ); to
cakephp orm and logging queries
Working with cakephp/orm library, I needed to log all the queries. Cakephp provides a way to do it via cakephp/log.
<?php use Cake\Log\Log; Log::config('queries', [ 'className' => 'File', 'path' => '/my/log/path/', 'file' => 'app', 'scopes' => ['queriesLog'] ]); But you are not limited, if you need to configure it to a PSR-3 logger like monolog/monolog
<?php use Cake\Log\Log; use Monolog\Logger; use Monolog\Handler\StreamHandler; Log::config('default', function () { $log = new Logger('cli'); $log->pushHandler(new StreamHandler('php://stdout')); return $log; }); That was pretty simple and it logs to cli.
cakephp orm and illuminate pagination
Do you know CakePHP version 3 has a lovely ORM which can be used as standalone?
Thank you José Lorenzo RodrÃguez and every contributor, for your hard work.
composer require cakephp/orm That's it.
Working on I noticed I need to do some pagination. Oh, remember we have illuminate/pagination. Why not use it?
Problem, there seems no one have implemented it. How could we achieve it? Lets do it.
composer require illuminate/pagination If you are using a psr-7 request / response here is the middleware for you.
eloquent and pagination inside zend expressive
Recently working with eloquent (Laravel's orm), zend expressive and zend view, I wanted to integrate pagination.
It was simple as registering a Paginator middleware.
<?php use Illuminate\Pagination\Paginator; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; IlluminatePaginator::currentPageResolver(function ($pageName) use ($request) { $params = $request->getQueryParams(); return empty($params[$pageName]) ? 1 : $params[$pageName]; }); IlluminatePaginator::currentPathResolver(function () use ($request) { return $request->getUri()->getPath(); }); and you can call paginate on the Model.
Eg : Consider you have a Post model.
integrating zend form in zend expressive and view
Example is based using Aura.Di. But the functionality will be same for any containers. First register the service Zend\View\HelperPluginManager, so that we can access the same object.
To register the form helpers, create the object of Zend\Form\View\HelperConfig and pass the Zend\View\HelperPluginManager service.
Example code with Aura.Di version 3 configuration.
<?php use Aura\Di\ContainerConfig; use Aura\Di\Container; use Zend\Form\View\HelperConfig; class ViewHelper extends ContainerConfig { public function define(Container $di) { $di->set('Zend\View\HelperPluginManager', $di->lazyNew('Zend\View\HelperPluginManager')); } public function modify(Container $di) { $serviceManager = $di->get('Zend\View\HelperPluginManager'); $helper = new HelperConfig(); $helper->configureServiceManager($servicemanager); } } Creating your own zend-view helper Create your helper class <?
custom events in symfony2 bundle
In this tutorial we will create a custom event for symfony2 bundle.
Assuming you have downloaded the symfony-standard distribution to play.
Create HktEventBundle via sensio generator bundle.
<?php php app/console generate:bundle --namespace=Hkt/EventBundle --dir src --no-interaction Create the event class.
<?php // src/Hkt/EventBundle/Event/PageViewed.php namespace Hkt\EventBundle\Event; use Symfony\Component\EventDispatcher\Event; class PageViewed extends Event { protected $name; public function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } } Add as many methods/properties which are needed from the listener.
20 years of php
First my apologies being late! I hope you all know PHP is celebrating its 20th years of existence in the web.
There is something that makes PHP unique that helps to standout with other languages.
In this opporchunity I would like to thank the creator, the contributors, the maintainers, and all the users (past/present) to make this memorable.
My Story I got an exposure to learn and use internet in my college days.